package com.zhny.aiot.xmn.conductivity.plugin;

import com.zhny.aiot.plugin.ICenterFacilities;
import com.zhny.aiot.plugin.IDevice;
import com.zhny.aiot.plugin.modbus.ModemServer;
import com.zhny.aiot.plugin.modbus.device.ModemConfig;
import com.zhny.aiot.plugin.modbus.device.ModemDeviceFactory;
import com.zhny.aiot.plugin.modbus.handler.model.ModemRequestMessage;
import com.zhny.aiot.plugin.model.DeviceEntity;
import com.zhny.aiot.plugin.model.FactoryType;
import com.zhny.aiot.plugin.model.StoreEntity;
import com.zhny.aiot.xmn.conductivity.plugin.model.ConductivityStoreEntry;
import org.pf4j.Extension;
import org.pf4j.Plugin;
import org.pf4j.PluginWrapper;

public class ConductivityPlugin extends Plugin {
    public ConductivityPlugin(PluginWrapper wrapper) {
        super(wrapper);
    }

    @Extension
    public static class ConductivityFactory extends ModemDeviceFactory<ConductivityStoreEntry> {

        public ModemRequestMessage getRequestMessage(ModemConfig modemConfig) {
            return new ModemRequestMessage(Integer.parseInt(modemConfig.getAddress()), (short) 3, 25, 2);
        }

        public IDevice createDevice(ICenterFacilities iCenterFacilities, DeviceEntity entity) {
            return new ConductivityDevice(ModemServer.getInstance().getEngine(), this, iCenterFacilities, entity);
        }

        public Class<? extends StoreEntity> storeClass() {
            return ConductivityStoreEntry.class;
        }

        public String getId() {
            return "xmn-conductivity-plugin";
        }

        public String getName() {
            return "希马诺电导率传感器插件";
        }

        public FactoryType getType() {
            return FactoryType.Integrate;
        }
    }
}
